package com.gp.service.impl;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gp.util.CommonResult;
import com.gp.dao.AdvertisePositionDao;
import com.gp.entity.AdvertisePosition;
import com.gp.service.AdvertisePositionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class AdvertisePositionServiceImpl implements AdvertisePositionService {
    @Resource
    private AdvertisePositionDao advertisePositionDao;

    //查询
    @Override
    public CommonResult findAll(Integer page, Integer limit, AdvertisePosition advertisePosition) {
        Page<AdvertisePosition> page1 = new Page<>(page, limit);
        QueryWrapper<AdvertisePosition> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(advertisePosition.getName())) {
            wrapper.like("name", advertisePosition.getName());
        }
        Page<AdvertisePosition> advertisePositionPage = advertisePositionDao.selectPage(page1, wrapper);

        return new CommonResult(200, "操作成功", advertisePositionPage);
    }

    //删除
    @Override
    public CommonResult deleteById(Integer id) {

        int i = advertisePositionDao.deleteById(id);

        if (i > 0) {
            return new CommonResult(200, "操作成功", i);
        } else {
            return new CommonResult(500, "操作失败", null);
        }
    }
    //修改
    @Override
    public CommonResult updateById(AdvertisePosition advertisePositione) {
        int i = advertisePositionDao.updateById(advertisePositione);

        if (i > 0) {
            return new CommonResult(200, "操作成功", i);
        } else {
            return new CommonResult(500, "操作失败", null);
        }
    }

    @Override
    public CommonResult insert(AdvertisePosition advertisePosition) {
        int i = advertisePositionDao.insert(advertisePosition);
        if (i > 0) {
            return new CommonResult(200, "操作成功", i);
        } else {
            return new CommonResult(500, "操作失败", null);
        }
    }
}
